import {ref, reactive} from 'vue'

export default function useScrollPosition() {
  const scrollX = ref(0)
  const scrollY = ref(0)
  // 或者使用reactive
  const scrollPosition = reactive({
    x: 0,
    y: 0
  })

  document.addEventListener('scroll', () =>{
    scrollX.value = window.scrollX
    scrollY.value = window.scrollY
    scrollPosition.x = window.scrollX
    scrollPosition.y = window.scrollY
  })
  return {
    scrollX,
    scrollY,
    scrollPosition
  }
}